//
//  TabbarViewController.m
//  MyProject
//
//  Created by 石小强 on 2018/3/20.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "TabbarViewController.h"
#import "EntryViewController.h"
#import "CashHomeViewController.h"
#import "MessageHomeVC.h"
#import "MySelfVC.h"
#import "YJMNavigationController.h"
#import "FindPeopleViewController.h"

@interface TabbarViewController ()<UITabBarControllerDelegate>

@end

@implementation TabbarViewController


static TabbarViewController *tabVC = nil;

+ (instancetype)sharedTBVC {
//    if(tabVC == nil)
//    {
//        tabVC = [[TabbarViewController alloc] init];
//    }
    tabVC = [[TabbarViewController alloc] init];
    return tabVC;
}

//+ (instancetype)sharedTBVC {
//    TabbarViewController *tabVC = [[TabbarViewController alloc] init];
//    return tabVC;
//}

+(void)releaseTBVC
{
    for (UIViewController * vc in tabVC.viewControllers) {
        [vc removeFromParentViewController];
    }
    tabVC = nil;
}
- (void)viewDidLoad {
    [super viewDidLoad];

    [self initSubControllers];
    
    self.tabBar.tintColor = UIColorFromRGB(0xffffff);
    self.delegate = self;
    [self.tabBar setBarTintColor:kBlackColor];
}

- (void)initSubControllers {
    
    FindPeopleViewController *find = [[FindPeopleViewController alloc]init];
    YJMNavigationController *findNav = [[YJMNavigationController alloc]initWithRootViewController:find];
    findNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"找人" image:IMAGE(@"ic_找人_unselect") selectedImage:IMAGE(@"ic_找人_select")];
    
    
    EntryViewController *homePage = [[EntryViewController alloc]init];
    YJMNavigationController *homeNav = [[YJMNavigationController alloc]initWithRootViewController:homePage];
    //    homeNav.navigationBarHidden = YES;
    homeNav.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"职位" image:IMAGE(@"ic_Frontpage_Unselected") selectedImage:IMAGE(@"ic_Frontpage_Selected")];
    
    
//    CashHomeViewController *homePage1 = [[CashHomeViewController alloc]init];
//    YJMNavigationController *homeNav1 = [[YJMNavigationController alloc]initWithRootViewController:homePage1];
//    homeNav1.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"变现" image:IMAGE(@"ic_Cash_Unselected") selectedImage:IMAGE(@"ic_Cash_Selected")];
    
    MessageHomeVC *homePage2 = [[MessageHomeVC alloc]init];
    YJMNavigationController *homeNav2 = [[YJMNavigationController alloc]initWithRootViewController:homePage2];
    homeNav2.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:IMAGE(@"ic_news_Unselected") selectedImage:IMAGE(@"ic_news_Selected")];
    
    MySelfVC *chatController = [[MySelfVC alloc]init];
    YJMNavigationController *homeNav3 = [[YJMNavigationController alloc]initWithRootViewController:chatController];
    homeNav3.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"我的" image:IMAGE(@"ic_me_Unselected") selectedImage:IMAGE(@"ic_me_Selected")];
    
    self.viewControllers =[NSArray arrayWithObjects:findNav,homeNav,homeNav2,homeNav3, nil];
//    self.viewControllers =[NSArray arrayWithObjects:homeNav,homeNav2,homeNav3, nil];
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    if ([viewController isKindOfClass:[YJMNavigationController class]]) {
        YJMNavigationController *nav = (YJMNavigationController *)viewController;
        for (NSInteger i = 0; i<nav.yjm_viewControllers.count; i++) {
            SaintiLog(@"%@",nav.yjm_viewControllers[i]);
            if ([nav.yjm_viewControllers[i] isKindOfClass:[MessageHomeVC class]]) {
                [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshMessage" object:nil];
                
            }
        }
    }
}

@end
